package servlets;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.DatabaseManager;

public class UpdateUserServlet extends HttpServlet {

	

	/**
	 * 
	 */
	private static final long serialVersionUID = 5017566268732293825L;

	//method to insert
	protected void doPut(HttpServletRequest request, HttpServletResponse response){
		String social, idUser, idSocial;
		
		social = request.getParameter("social");
		idUser = request.getParameter("idUser");
		idSocial = request.getParameter("idSocial");
		
		DatabaseManager databaseManager;
		databaseManager = new DatabaseManager();
		databaseManager.connect();
		try {
			databaseManager.updateUser(idUser, social, idSocial);
			response.getWriter().write("{\n\t\"errors\":\"no\"\n}");
				
		} catch (Exception e) {
			try {
				response.getWriter().write("{\n\t\"errors\":\"yes\"\n}");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
		databaseManager.closeConnection();
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
		
	}
		
}
